<template>
	<view>
		<view class="courier-number">
			<view class="fillinvoice">
				<span>抬头类型</span>
				<radio-group @change="radioChange" class="radio-group">
					<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in items" :key="item.value">
						<view class="radio">
							<radio :value="item.value" :checked="index === enterprise.type" color="#077840" />
						</view>
						<view class="name">{{item.name}}</view>
					</label>
				</radio-group>
			</view>
			<view class="fillinvoice" v-if="enterprise.type==1">
				<span> 抬头名称</span>
				<input type="text" v-model="enterprise.risePesonal" placeholder="建议填写个人姓名/店名" />
			</view>

			<view v-if="enterprise.type==0">
				<view class="fillinvoice">
					<span> 公司抬头</span>
					<input type="text" v-model="enterprise.rise" placeholder="请填写公司抬头" />
				</view>
				<view class="fillinvoice">
					<span> 公司税号</span>
					<input type="text" v-model="enterprise.duty" placeholder="请填写公司税号" />
				</view>
				<view class="fillinvoice">
					输入完整抬头信息，已开具增值税专用发票

				</view>
			</view>

		</view>
		<view class="courier-number" v-if="enterprise.type==0">

			<view class="fillinvoice fillinvoice1 ">
				<span> 公司地址</span>
				<input type="text" v-model="enterprise.address" placeholder="请填写公司地址" />
			</view>
			<!-- <input type="text" v-model="enterprise.phone" placeholder="请填写公司电话" /> -->

			<view class="fillinvoice fillinvoice1 ">
				<span> 公司电话</span>
				<input type="text" v-model="enterprise.phone" placeholder="请填写公司电话" />
			</view>
			<view class="fillinvoice fillinvoice1 ">
				<span> 开户银行</span>
				<input type="text" v-model="enterprise.bank" placeholder="请填写开户银行" />
			</view>
			<view class="fillinvoice fillinvoice1 ">
				<span> 开户账号</span>
				<input type="text" v-model="enterprise.account" placeholder="请填写开户账号" />
			</view>
		</view>
		<view class="courier-box">
			<view class="courier emial">
				<span> 电子邮箱</span>
				<input type="text" style="width: 544rpx;" v-model="enterprise.email" placeholder="请填写接收发票的电子邮箱" />
			</view>
		</view>
		<view class="submit" @click="submit">提交</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				items: [{
						value: '1',
						name: '企业单位'
					},
					{
						value: '2',
						name: '个人/非企业单位',

					},
				],
				// current: 0,
				courierNumber: '',
				courierCompany: '',
				enterprise: {
					goodsId: '',
					type: 0,
					risePesonal: '',
					rise: '',
					email: '',
					duty: '',
					address: '',
					phone: '',
					bank: "",
					account: '',
					orderId: ''

				},

			};
		},
		onLoad(option) {
			this.enterprise.goodsId = JSON.parse(option.id).join(',')
			this.enterprise.orderId = option.orderId
		},
		onShareAppMessage(option) {
			return {
				title: '上云丰花卉',
				path: '/pages/index/index'
			}
		},
		onShareTimeline(option) {
			return {
				title: '上云丰花卉',
				path: '/pages/index/index'
			}
		},
		methods: {
			// 单选按钮点击事件
			radioChange: function(evt) {
				for (let i = 0; i < this.items.length; i++) {
					if (this.items[i].value === evt.target.value) {
						this.enterprise.type = i;

						break;
					}
				}
			},
			// 提交
			submit() {
				console.log(this.enterprise);
				// type	抬头类型(0：企业单位，1：个人/非企业单位)
				if (this.enterprise.type == 0) {
					// 企业发票
					if (!this.enterprise.rise) {
						uni.showToast({
							title: '请输入公司抬头'
						});
						this.tui.toast('')
					} else if (!this.enterprise.duty) {
						uni.showToast({
							title: '请输入公司税号'
						});
					} else if (!this.enterprise.address) {
						uni.showToast({
							title: '请输入公司地址'
						});
					} else if (!this.enterprise.phone) {
						uni.showToast({
							title: '请输入公司电话'
						});
					} else if (!this.enterprise.bank) {
						uni.showToast({
							title: '请输入开户银行'
						});
					} else if (!this.enterprise.account) {
						uni.showToast({
							title: '请输入开户账号'
						});
					} else if (!this.enterprise.email) {
						uni.showToast({
							title: '请输入电子邮箱'
						});
					} else {
						this._postBody('user/user/invoice', this.enterprise,
							function(res) {
								console.log(res.data)
								uni.showToast({
									title: '开票成功'
								});
								setTimeout(()=>{
									uni.$emit('upApply')
									uni.navigateBack({
										delta: 1
									})
								},1500)
							})

					}
				} else {
					if (!this.enterprise.risePesonal) {
						uni.showToast({
							title: '请填写个人姓名/店名'
						});
					} else if (!this.enterprise.email) {
						uni.showToast({
							title: '请输入电子邮箱'
						});
					} else {
						this._postBody('user/user/invoice', this.enterprise,
							function(res) {
								console.log(res.data)
								uni.showToast({
									title: '开票成功'
								});
								setTimeout(()=>{
									uni.$emit('upApply')
									uni.navigateBack({
										delta: 1
									})
								},1500)
							})
					}
				}
			}
		}
	}
</script>
<style lang="less">
	page {
		background-color: #F9F9F9;
	}
</style>
<style lang="less" scoped>
	.courier-number {
		width: 100%;
		// height: 200rpx;
		background: #FFFFFF;
		line-height: 100rpx;
		box-sizing: border-box;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #999999;
		margin-bottom: 30rpx;

		.fillinvoice {
			display: flex;
			width: 690rpx;
			height: 100rpx;
			margin: 0 auto;
			border-top: 2px solid #EEEEEE;
			box-sizing: border-box;
			line-height: 100rpx;

			input {
				width: 80%;
				height: 100rpx;
				margin-left: 20rpx;
				color: #333333;

				.input-placeholder {
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
				}
			}

			.input {
				margin-left: 0;

				.input-placeholder {
					font-size: 24rpx;
				}
			}
		}

		.fillinvoice1 {
			border-top: 0;
			border-bottom: 2px solid #EEEEEE;
		}

		.fillinvoice1:last-child {
			border-bottom: 0;
		}

		.radio-group {
			display: inline-block;

			view {
				display: inline-block;
			}

			.radio {
				margin-left: 20rpx;
			}

			.name {
				margin-right: 50rpx;
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #333333;
			}
		}
	}

	.courier {
		display: flex;
		width: 100%;
		padding-left: 30rpx;
		// padding: 30rpx 0;
		box-sizing: border-box;
		height: 100rpx;
		line-height: 100rpx;
		background: #FFFFFF;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #999999;

		input {
			height: 100rpx;
			margin-left: 20rpx;
			color: #333333;

			.input-placeholder {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #999999;
			}
		}
	}

	.emial {
		margin-bottom: 30rpx;
	}

	.submit {
		width: 630rpx;
		height: 96rpx;
		background: #077840;
		border-radius: 8rpx;
		margin: 0 auto;
		font-size: 32rpx;
		line-height: 96rpx;
		text-align: center;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}
</style>